package com.ktgj.flight.controller;

import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.flight.domain.AirportTerminal;
import com.ktgj.flight.service.IAirportTerminalService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 航站楼Controller
 * 
 * @author ruoyi
 * @date 2021-08-30
 */
@ControllerAdvice
@RestController
@RequestMapping("/terminal")
public class AirportTerminalController extends BaseController
{
    @Autowired
    private IAirportTerminalService airportTerminalService;

    /**
     * 查询航站楼列表
     */
    //@PreAuthorize(hasPermi = "flight:terminal:list")
    @GetMapping("/list")
    public TableDataInfo list(AirportTerminal airportTerminal)
    {
        startPage();
        List<AirportTerminal> list = airportTerminalService.selectAirportTerminalList(airportTerminal);
        return getDataTable(list);
    }

    /**
     * 导出航站楼列表
     */
    //@PreAuthorize(hasPermi = "flight:terminal:export")
    @Log(title = "航站楼", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AirportTerminal airportTerminal) throws IOException
    {
        List<AirportTerminal> list = airportTerminalService.selectAirportTerminalList(airportTerminal);
        ExcelUtil<AirportTerminal> util = new ExcelUtil<AirportTerminal>(AirportTerminal.class);
        util.exportExcel(response, list, "航站楼数据");
    }

    /**
     * 获取航站楼详细信息
     */
    //@PreAuthorize(hasPermi = "flight:terminal:query")
    @GetMapping(value = "/{terminalId}")
    public AjaxResult getInfo(@PathVariable("terminalId") Long terminalId)
    {
        return AjaxResult.success(airportTerminalService.selectAirportTerminalById(terminalId));
    }

    /**
     * 获取航站楼详细信息（远程）
     */
    @PostMapping("/getInfoById")
    public AirportTerminal getInfoById(@RequestBody Map<String, Object> map) {
        Long terminalId = Long.valueOf(map.get("id").toString());
        AirportTerminal airportTerminal = airportTerminalService.selectAirportTerminalById(terminalId);
        return airportTerminal;
    }

    /**
     * 新增航站楼
     */
    //@PreAuthorize(hasPermi = "flight:terminal:add")
    @Log(title = "航站楼", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AirportTerminal airportTerminal)
    {
        return toAjax(airportTerminalService.insertAirportTerminal(airportTerminal));
    }

    /**
     * 修改航站楼
     */
    //@PreAuthorize(hasPermi = "flight:terminal:edit")
    @Log(title = "航站楼", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AirportTerminal airportTerminal)
    {
        return toAjax(airportTerminalService.updateAirportTerminal(airportTerminal));
    }

    /**
     * 删除航站楼
     */
    //@PreAuthorize(hasPermi = "flight:terminal:remove")
    @Log(title = "航站楼", businessType = BusinessType.DELETE)
	@DeleteMapping("/{terminalIds}")
    public AjaxResult remove(@PathVariable Long[] terminalIds)
    {
        return toAjax(airportTerminalService.deleteAirportTerminalByIds(terminalIds));
    }

    @PostMapping("/queryStartTerminal")
    public String queryStartTerminal(@RequestParam("terminalId") Long terminalId) {
        String terminal = airportTerminalService.queryStartTerminal(terminalId);
        return terminal;
    }

    /**
     * 获取航站楼id
     */
    @PostMapping("/getInfoByName")
    public AirportTerminal getInfoByName(@RequestBody Map<String, Object> map) {
        String name = map.get("name").toString();
        AirportTerminal airportTerminal = airportTerminalService.selectAirportTerminalByName(name);
        return airportTerminal;
    }
}
